﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gfw.Models.Stock;
using Gfw.Repository;
using NHibernate;

namespace Gfw.Repositories.Stock
{
    public class TendencyRepository : Repository<StkTendency>
    {
        public virtual StkTendency GetTendency(DateTime date, int tendencyType, UnitOfWork work = null)
        {
            ISession session = work == null ? Session : work.Session;
            var hql = "from StkTendency where TendencyDate=:date and TendencyType=:type";
            var query = session.CreateQuery(hql).SetDateTime("date", date)
                .SetInt32("type", tendencyType);
            return query.List<StkTendency>().FirstOrDefault();
        }

        public  IList<StkTendency> GetTendency30(int tendencyType)
        {
            var hql = "from StkTendency where  TendencyType=:type order by TendencyDate desc";
            var query = Session.CreateQuery(hql).SetInt32("type", tendencyType).SetCacheMode(CacheMode
                .Ignore).SetMaxResults(30).List<StkTendency>();
            return query.Reverse().ToList();
        }
    }
}
